package com.android.measuringimportanceoflectureslides.builder;

import android.app.Activity;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;

import com.android.measuringimportanceoflectureslides.MainActivity;
import com.android.measuringimportanceoflectureslides.R;
import com.android.measuringimportanceoflectureslides.data.Database;
import com.android.measuringimportanceoflectureslides.data.SimpleList;



public class ToMakeBuilder extends Activity{
	Toast toast;
	Context mContext;
	Builder builder;
	String fileName;
	Database mDatabase;
			
	public ToMakeBuilder(Context context, Database database){
		this.mContext = context;
		this.mDatabase = database;
		builder = new Builder(this.mContext);
	}
	
	public void buildDialog(){
		View view = View.inflate(mContext, R.layout.layout_for_dialog_file_name, null) ;
			
		builder.setView(view);
    	builder.setTitle(R.string.txt_dialog_title_enter_name_of_to_capture_slides)
    			.setPositiveButton(R.string.txt_dialog_btn_create, 
    		            new DialogInterface.OnClickListener(){   
    		            	public void onClick(DialogInterface dialog, int which){
    		            		
    		            		Dialog source = (Dialog) dialog;
    		            		EditText nameField = (EditText) source
    		              				.findViewById(R.id.txtFieldLayoutForDialogFileName);
    		            		fileName = nameField.getText().toString();

    		            		if (fileName.length() > 0){
   		            			mDatabase.addFileNameToDatabase(fileName);
    		            			
   		            			if(MainActivity.debug == 1){
   		            				toast = Toast.makeText(mContext, "filname:" + fileName , Toast.LENGTH_LONG);
    		            				toast.show();
    		            			}
    		            		}
                        		dialog.dismiss();
    		            	}
    		            });

    	builder.setNegativeButton(R.string.lbl_cancel_btn,
                new DialogInterface.OnClickListener(){
                    public void onClick(DialogInterface dialog, int which){
                        dialog.dismiss();
                    }
                });
    	builder.show();
    }
}
